<template>
	<div>

		<el-row :gutter="24">
			<el-col :span="6">
				<el-row :gutter="24">
					<el-col :span="24" style="padding-right: 5px!important;padding-left: 15px!important">
						<el-input size="small" placeholder="请输入内容" v-model="deptFilterValue" icon="search" @click="deptTreeFilter"></el-input>

					</el-col>
				</el-row>
				<el-row :gutter="24">
					<el-col :span="24">
						<el-tree :data="deptTreeData" :highlight-current=true :props="defaultProps" accordion ref='deptTree' :filter-node-method="filterNode" @node-click="deptNodeClick"></el-tree>
					</el-col>
				</el-row>
			</el-col>
			<el-col :span="18">
				<el-row :gutter="24">
					<el-col :span="1" style="margin-right:10px;">
						<p class="queryLabel">手机号:</p>
					</el-col>
					<el-col :span="4">
						<el-input v-model="mobile" size="small" placeholder=""></el-input>
					</el-col>
					<el-col :span="1" style="margin-right:10px;">
						<p class="queryLabel">姓名:</p>
					</el-col>
					<el-col :span="4">
						<el-input v-model="uName" size="small" placeholder=""></el-input>
					</el-col>
					<el-col :span="2" style="margin-right:-10px;">
						<p class="queryLabel">登录账户:</p>
					</el-col>
					<el-col :span="4">
						<el-input v-model="uCode" size="small" placeholder=""></el-input>
					</el-col>
					<el-col :span="3" style="margin-left: -20px;">
						<el-button type="primary" size="small" @click="queryDeptUser">查询</el-button>

					</el-col>
				</el-row>
				<el-row>
					<el-row>
						<el-col :span="24" style="text-align: right;" v-if="buttonShow">
							<el-button type="primary" size="small" v-on:click="add" style="margin-left: 10px;" v-if="addShow">新增</el-button>
							<el-button type="primary" size="small" v-on:click="updateDept" style="margin-left: 10px;" v-if="addShow">调整部门</el-button>
							<el-button type="primary" size="small" @click.native.prevent="edit()">编辑</el-button>
							<el-button type="primary" size="small" @click.native.prevent="start()">启用</el-button>
							<el-button type="primary" size="small" @click.native.prevent="stop()">停用</el-button>
							<el-button type="primary" size="small" @click.native.prevent="editResRole()">分配资源角色</el-button>
							<el-button type="primary" size="small" @click.native.prevent="editDataRole()">分配数据角色</el-button>
							<el-button type="primary" size="small" @click.native.prevent="editRes()">分配访问资源</el-button>
							<el-button type="primary" size="small" @click.native.prevent="editPass()">修改密码</el-button>
						</el-col>
					</el-row>
					<el-col :span="24" style="padding-right: 0px!important;padding-left: 0px!important;">
						<el-table :data="userGrid.dataList" style="width:100%;height:460px;" stripe @selection-change="handleSelectionChange">
							<el-table-column type="selection" width="60" fixed>
							</el-table-column>
							<el-table-column prop="uCode" label="登录账号" width="120">
							</el-table-column>
							<el-table-column prop="uName" label="用户姓名" width="120">
							</el-table-column>
							<el-table-column prop="uSex" label="性别" :formatter="sexCov" width="80">
							</el-table-column>
							<el-table-column prop="uMobile" label="手机号" width="150" align="right">
							</el-table-column>
							<el-table-column prop="createTime" label="创建日期" width="150" :formatter="timeCov" align="center">
							</el-table-column>
							<el-table-column prop="status" label="状态" :formatter="statusCov" width="150">
							</el-table-column>
							</el-tooltip>

						</el-table>
						<el-pagination small @current-change="userPageChange" :current-page="userCurentPage" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="userGrid.total">
						</el-pagination>
					</el-col>
				</el-row>
			</el-col>
		</el-row>

		<!---->
		<!--用户表单 -->
		<el-dialog title="用户信息" v-model="userFormShow" size="small">
			<el-row>
				<el-form :model="userFormData" ref="userForm" :rules="userRule" label-width="120px">
					<el-col :span="12">
						<el-form-item label="登录账户" required prop="uCode">
							<el-input size="small" v-model="userFormData.uCode"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="用户姓名" prop="uName" required>
							<el-input size="small" v-model="userFormData.uName"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="输入密码" required prop="uPassword">
							<el-input type="password" size="small" v-model="userFormData.uPassword" :disabled="canPassEdit"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="再次输入密码" required prop="uPassword">
							<el-input type="password" size="small" v-model="userFormData.uPassword_2" :disabled="canPassEdit"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="性别" required prop="uSex">
							<el-select size="small" v-model="userFormData.uSex" placeholder="请选择">
								<el-option v-for="item in sexComboData" :label="item.label" :value="item.value"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="出生日期" required prop="uBirthDate">
							<el-date-picker size="small" v-model="userFormData.uBirthDate" format="yyyy-MM-dd" :editable=false type="date" placeholder="选择日期">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="手机号" prop="uMobile">
							<el-input size="small" v-model="userFormData.uMobile"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="办公电话" prop="uTelPhone">
							<el-input size="small" v-model="userFormData.uTelPhone"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="电子邮箱" prop="uEmail">
							<el-input size="small" v-model="userFormData.uEmail"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="入职日期" prop="uJoinDate">
							<el-date-picker size="small" v-model="userFormData.uJoinDate" format="yyyy-MM-dd" :editable=false type="date" placeholder="选择日期">
							</el-date-picker>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
			<div slot="footer" class="dialog-footer">
				<el-button @click="userFormShow = false">取 消</el-button>
				<el-button type="primary" @click="saveUser">提 交</el-button>
			</div>
		</el-dialog>
		<!-- 分配访问角色 -->
		<!-- 分配访问资源-->
		<el-dialog title="分配访问角色" v-model="resRoleShow" size="small">
			<el-row>
				<el-col :span="9">
					角色信息
				</el-col>
				<el-col :span="15">
					关联资源
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="9" style="overflow-y: scroll;height: 600px;">
					<el-tree :data="resRoleTreeData" @node-click="roleNodeClick" ref="resRoleTree" :highlight-current=true :props="resRoleProps" accordion :auto-expand-parent=false :default-checked-keys="checkedResRoleKey" show-checkbox node-key="id"></el-tree>
				</el-col>
				<el-col :span="15" style="padding-left: 5px">
					<el-tree :data="roleCheckedResTreeData" :highlight-current=true :props="resProps" accordion :auto-expand-parent=false :default-checked-keys="checkedResKey" node-key="id"></el-tree>
				</el-col>
			</el-row>
			<div slot="footer" class="dialog-footer">
				<el-button @click="resRoleShow = false">取 消</el-button>
				<el-button type="primary" @click="saveResRole">提 交</el-button>
			</div>
		</el-dialog>
		<!-- 分配数据角色 -->
		<!-- 分配访问资源-->
		<el-dialog title="分配数据角色" v-model="dataRoleShow" size="small">
			<el-row>
				<el-col :span="9">
					数据角色信息
				</el-col>
				<el-col :span="15">
					关联部门或用户
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="9" style="overflow-y: scroll;height: 600px;">
					<el-tree :data="dataRoleTreeData" @node-click="dataRoleNodeClick" ref="dataRoleTree" :highlight-current=true :props="dataRoleProps" accordion :auto-expand-parent=false :default-checked-keys="checkedDataRoleKey" show-checkbox node-key="id"></el-tree>
				</el-col>
				<el-col :span="15" style="padding-left: 5px">
					<el-tree :data="dataRoleCheckedTreeData" :highlight-current=true :props="dataOrgProps" accordion :auto-expand-parent=false node-key="id"></el-tree>
				</el-col>
			</el-row>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dataRoleShow = false">取 消</el-button>
				<el-button type="primary" @click="saveDataRole">提 交</el-button>
			</div>
		</el-dialog>
		<!-- 分配访问资源-->
		<el-dialog title="分配访问资源" v-model="resTreeShow" size="small">
			<el-tree :data="resTreeData" ref="resTree" :highlight-current=true :props="resProps" accordion :auto-expand-parent=false :default-checked-keys="checkedResKey" show-checkbox :check-strictly="true" node-key="id"></el-tree>
			<div slot="footer" class="dialog-footer">
				<el-button @click="resTreeShow = false">取 消</el-button>
				<el-button type="primary" @click="saveRes">提 交</el-button>
			</div>
		</el-dialog>

		<!-- 调整部门-->
		<el-dialog title="调整部门" v-model="deptShow" size="small">
			<el-tree :data="tzDeptTreeData" ref="tzDeptTree" :highlight-current=true :props="deptProps" accordion :auto-expand-parent=false highlight-current node-key="id" @node-click="checkedDept"></el-tree>
			<div slot="footer" class="dialog-footer">
				<el-button @click="deptShow = false">取 消</el-button>
				<el-button type="primary" @click="saveTzDept">提 交</el-button>
			</div>
		</el-dialog>
		<!--
																																																																	                                                                        修改密码
																																																																		                                                                    -->
		<el-dialog title="修改密码" v-model="passFormShow" size="small">
			<el-form :model="passFormData" ref="passForm" :rules="passRule" label-width="120px">
				<el-form-item label="输入密码" required prop="newPass">
					<el-input size="small" v-model="passFormData.newPass"></el-input>
				</el-form-item>
				<el-form-item label="再次确认密码" required prop="confirmPass">
					<el-input size="small" v-model="passFormData.confirmPass"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="passFormShow = false">取 消</el-button>
				<el-button type="primary" @click="savePass">提 交</el-button>
			</div>
		</el-dialog>
	</div>
</template>
<script>
import md5 from 'md5'
export default {
	data: function() {
		return {
			//anniuxianshi
			buttonShow: false,
			addShow: false,


			//性别
			sexComboData: [{
				label: "男",
				value: "0"
			}, {
				label: "女",
				value: "1"
			}],

			mobile: '',
			uCode: '',
			uName: '',

			//分页设置
			page: this.page,
			//当前页
			userCurentPage: 1,
			//表格查询条件
			searchValue: '',
			//树型数据配置
			defaultProps: {
				children: 'child',
				label: 'oName'
			},
			//定义空数组，来判断 单选 选中哪一个
			multipleSelection: [],
			//树型查询条件
			treeQueryValue: '',

			//树型数据
			deptTreeData: [],

			//表格数据
			userGrid: {
				total: 0,
				dataList: []
			},

			//公司下级
			comChild: [],
			//部门下级
			deptChild: [],
			//部门表单是否显示
			userFormShow: false,

			//用户Form 数据
			userFormData: {
				id: '',
				uCode: '',
				uName: '',
				uPassword: '',
				uPassword_2: '',
				uMobile: '',
				uTelPhone: '',
				uBirthDate: '',
				uJoinDate: '',
				uSex: '',
				uEmail: '',
				oId: '',

				uStatus: '1',
				createTime: 0,
				createUser: '',
				updateTime: 0,
				updateUser: '',
			},
			//资源 Form 空数据
			userEmptyData: {
				id: '',
				uCode: '',
				uName: '',
				uPassword: '',
				uPassword_2: '',
				uMobile: '',
				uTelPhone: '',
				uBirthDate: '',
				uJoinDate: '',
				uSex: '',
				uEmail: '',
				oId: '',
				uStatus: '1',
				createTime: 0,
				createUser: '',
				updateTime: 0,
				updateUser: '',

			},

			//品牌是否可编辑
			canPassEdit: false,
			//区域转换

			//当前组织节点、与组织类型
			curTreeDeptId: '',
			curTreeDeptType: '',

			/**
			 * 分配访问角色
			 */
			resRoleShow: false,
			checkedResRoleKey: [],
			//调整部门让
			deptShow: false,
			tzDeptTreeData: [],
			checkedDeptKey: [],
			tzDeptKey: '',
			deptProps: {
				children: "child",
				label: "oName"
			},
			//树型数据配置
			resRoleProps: {
				children: 'child',
				label: 'rName'
			},
			//角色对应的资源树
			roleCheckedResTreeData: [],
			//角色树
			resRoleTreeData: [],

			/**
			 * 分配数据角色
			 */
			dataRoleShow: false,
			checkedDataRoleKey: [],
			//树型数据配置
			dataRoleProps: {
				children: 'child',
				label: 'roleName'
			},
			//分配的数据角色
			dataRoleCheckedTreeData: [],
			roleCheckedOrgTreeData: [],
			//数据角色树
			dataRoleTreeData: [],
			dataOrgProps: {
				children: "child",
				label: "oName"
			},
			/**
			 * 分配资源
			 *
			 */
			resTreeShow: false,
			checkedResKey: [],
			//树型数据配置
			resProps: {
				children: 'child',
				label: 'resName'
			},
			resTreeData: [],
			/**表单相关
			 * 修改密码
			 *
			 **/
			passFormShow: false,
			passFormData: {
				id: "",
				newPass: "",
				confirmPass: "",
			},
			passFormEmpty: {
				id: '',
				newPass: "",
				confirmPass: "",
			},
			//组织表单较验规则
			passRule: {
				newPass: [{
					required: true,
					message: '请输入密码',
					trigger: 'blur'
				}],
				confirmPass: [{
					required: true,
					message: '请再次输入密码',
					trigger: 'blur'
				}],

			},
			//组织表单较验规则
			userRule: {

				uCode: [{
					required: true,
					message: '登录账户不能为空',
					trigger: 'blur'
				}],
				uName: [{
					required: true,
					message: '用户姓名不能为空',
					trigger: 'blur'
				}],
				uPassword: [{
					required: true,
					message: '请输入密码',
					trigger: 'blur'
				}],
				uPassword_2: [{
					required: true,
					message: '请再次输入密码',
					trigger: 'blur'
				}],
				uMobile: [{
					required: true,
					message: '请输入手机号',
					trigger: 'blur'
				}],
				uSex: [{
					required: true,
					message: '请选择性别',
					trigger: 'blur'
				}],

				oId: [{
					required: true,
					message: '请选择部门',
					trigger: 'blur'
				}],

			},
			//当前用户
			currentUser: '',

			//部门树的查询条件
			deptFilterValue: '',
		}
	},
	methods: {

		//查询部门树
		queryDeptTree: function() {
			//获取部门资源树
			this.$http.get(this.API_ROOT + '/rbac/dept/tree', {}).then((response) => {
				this.$data.deptTreeData = response.data.dataList;
				if (response.data.dataList.length > 0) {
					if (!response.data.success) {
						this.$message(response.data.msg);
						return;
					}
					//
					this.$data.curTreeDeptId = response.data.dataList[0].id;
					//存在数据，则查询最上级部门的用户
					this.queryDeptUser();
				}

			}, (response) => { });
		},


		//点击部门节点
		deptNodeClick: function(data) {
			this.$data.curTreeDeptId = data.id;
			this.$data.curTreeDeptType = data.oType;
			this.queryDeptUser();
		},

		//根据部门 ID，查询用户
		queryDeptUser: function() {

			this.$http.get(this.API_ROOT + '/rbac/user/page', {
				params: {
					mobile: this.$data.mobile,
					code: this.$data.uCode,
					name: this.$data.uName,
					start: this.$data.userCurentPage,
					limit: this.$data.page.pageSize,
					oId: this.$data.curTreeDeptId
				}
			}).then((response) => {
				if (!response.data.success) {
					this.$data.buttonShow = false;
				} else {
					this.$data.userGrid.dataList = response.data.dataList; //Object.assign(this.$data.deptTabelData, response.data.dataList);
					this.$data.userGrid.total = Number(response.data.total);
					this.$data.buttonShow = true;
					if (response.data.addFlag == true) {
						this.$data.addShow = true;
					} else {
						this.$data.addShow = false;
					}
				}

			}, (response) => { });
		},
		//用户列表页签变化
		userPageChange: function(currentPage) {
			this.$data.userCurentPage = currentPage;
			this.queryDeptUser();
		},
		//复选框回调函数
		handleSelectionChange: function(val) {
			debugger;
			this.$data.multipleSelection = val;
		},
		reminderDelte: function() {
			debugger;
			if (this.$data.multipleSelection.length == 1) {
				this.openRemind(this.$data.multipleSelection[0].id)
			} else {
				this.$message.error("请选择一条数据")
			}
		},

		//启用资源
		start: function() {
			if (this.$data.multipleSelection.length == 1) {
				var data = this.$data.multipleSelection[0].id;
				this.$http({
					method: 'POST',
					url: this.API_ROOT + '/rbac/user/start',
					params: {
						id: data,
					}
				}).then(function(resp) {
					this.$message(resp.data.msg);
					this.queryDeptUser();
				}, function(error) {
					// error
				})
			} else {
				this.$message.error("请选择一条数据")
			}


		},
		//停用资源
		stop: function() {
			if (this.$data.multipleSelection.length == 1) {
				var data = this.$data.multipleSelection[0].id;
				this.$http({
					method: 'POST',
					url: this.API_ROOT + '/rbac/user/stop',
					params: {
						id: data,
					}
				}).then(function(resp) {
					this.$message(resp.data.msg);
					this.queryDeptUser();
				}, function(error) {
					// error
				})
			} else {
				this.$message.error("请选择一条数据")
			}


		},

		/*********
		 * 数据角色
		 * ***********/
		dataRoleNodeClick: function(data) {
			this.queryRoleCheckedOrgTree(data.id, data.roleType);
		},
		queryRoleCheckedOrgTree: function(id, roleType) {
			//获取资源树
			this.$http.get(this.API_ROOT + '/rbac/dataRole/orgTree', {
				params: {
					id: id,
					type: roleType
				}

			}).then((response) => {
				this.$data.dataRoleCheckedTreeData = response.data.dataList;
			}, (response) => { });
		},

		/**
		 * 获取访问角色
		 * ***/

		//查询访问角色树
		queryResRoleTree: function() {
			//获取资源树
			this.$http.get(this.API_ROOT + '/rbac/role/tree', {}).then((response) => {
				var rspData = response.data.dataList;
				this.$data.resRoleTreeData = rspData;
				if (rspData.length > 0) {
					//this.queryRoleCheckedResTree(rspData[0].id);
				}
			}, (response) => { });

		},
		//角色树点击
		roleNodeClick: function(data) {
			this.queryRoleCheckedResTree(data.id);
		},
		//查询角色选中的资源树
		queryRoleCheckedResTree: function(rId) {
			//获取资源树
			this.$http.get(this.API_ROOT + '/rbac/role/resTree', {
				params: {
					rId: rId
				}

			}).then((response) => {
				this.$data.roleCheckedResTreeData = response.data.dataList;
			}, (response) => { });

		},

		//获取已选中的值
		queryCheckedRole: function(id, type) {
			debugger;
			//获取资源树
			this.$http.get(this.API_ROOT + '/rbac/user/role', {
				params: {
					id: id,
					type: type
				}
			}).then((response) => {
				if (!response.data.success) {
					this.$message(response.data.msg);
					return;
				}
				if (type == "0") {
					this.$data.checkedResRoleKey = response.data.dataList;
					this.$refs.resRoleTree.setCheckedKeys(response.data.dataList);
				} else {
					this.$data.checkedDataRoleKey = response.data.dataList;
					this.$refs.dataRoleTree.setCheckedKeys(response.data.dataList);
				}

			}, (response) => { });
		},

		/**
		 * 分配数据角色
		 * **/
		queryDataRoleTree: function() {
			//获取资源树
			this.$http.get(this.API_ROOT + '/rbac/dataRole/tree', {
				params: {
					type: '1'
				}
			}).then((response) => {
				this.$data.dataRoleTreeData = response.data.dataList;
			}, (response) => { });
		},

		/**
		 * 获取资感觉
		 * ***/
		queryResTree: function() {
			//获取资源树
			this.$http.get(this.API_ROOT + '/rbac/res/userResTree', {}).then((response) => {
				this.$data.resTreeData = response.data.dataList;
			}, (response) => { });
		},
		queryCheckRes: function(id) {
			//获取资源树
			this.$http.get(this.API_ROOT + '/rbac/user/res', {
				params: {
					id: id
				}
			}).then((response) => {
				if (!response.data.success) {
					this.$message(response.data.msg);
					return;
				}
				this.$data.checkedResKey = response.data.dataList;
				this.$refs.resTree.setCheckedKeys(response.data.dataList);
			}, (response) => { });
		},
		//新增
		add: function() {
			this.$data.userFormData = Object.assign(this.$data.userFormData, this.$data.userEmptyData)
			this.$data.userFormData.oId = this.$data.curTreeDeptId;
			this.$data.canPassEdit = false;
			this.$data.userFormShow = true;
		},
		//编辑
		edit: function() {
			if (this.$data.multipleSelection.length == 1) {
				this.$data.userFormData = Object.assign(this.$data.userFormData, this.$data.userEmptyData);
				var data = this.$data.multipleSelection[0].id;
				this.$http.get(this.API_ROOT + '/rbac/user/info', {
					params: {
						id: data,
					}
				}).then(function(resp) {
					this.$data.canPassEdit = true;
					this.$data.userFormData = Object.assign(this.$data.userFormData, resp.data.data);
					this.$data.userFormShow = true;
					this.$data.userFormData.uPassword_2 = this.$data.userFormData.uPassword;

				}, function(error) { })
			} else {
				this.$message.error("请选择一条数据")
			}



		},
		//保存用户
		saveUser: function(index) {
			var length = this.$data.userFormData.uMobile.length;
			if (length == '11') {
				this.$refs.userForm.validate(function(valid) {
					if (valid) {
						var uPassword = this.$data.userFormData.uPassword;
						var uPassword_2 = this.$data.userFormData.uPassword;
						if (uPassword != uPassword_2) {
							this.$message.error("两次密码输入不一致，请重新输入！")
							return;
						}
						this.$data.userFormData.uPassword = md5(this.$data.userFormData.uPassword);
						this.$data.userFormData.uPassword_2 = md5(this.$data.userFormData.uPassword);
						//出生日期
						if (this.$data.userFormData.uBirthDate) {
							this.$data.userFormData.uBirthDate = this.moment(this.$data.userFormData.uBirthDate).format("YYYY-MM-DD");
						}
						//出生日期
						if (this.$data.userFormData.uJoinDate) {
							this.$data.userFormData.uJoinDate = this.moment(this.$data.userFormData.uJoinDate).format("YYYY-MM-DD");
						}

						this.$http.post(this.API_ROOT + '/rbac/user/save', this.$data.userFormData)
							.then(resp => {
								if (resp.data.success) {
									this.$message(resp.data.msg);
									this.queryDeptUser();
									this.$data.userFormShow = false;
								} else {
									this.$message.error(resp.data.msg);
								}
							}, resp => {

							});
					}
					return false;
				}.bind(this));
			} else {
				this.$message.error("请输入正确的手机号！")
			}

		},

		//queryDept
		//查询部门树
		queryTzDeptTree: function() {
			//获取部门资源树
			this.$http.get(this.API_ROOT + '/rbac/dept/tree', {}).then((response) => {
				this.$data.tzDeptTreeData = response.data.dataList;
				if (response.data.dataList.length > 0) {
					if (!response.data.success) {
						this.$message(response.data.msg);
						return;
					}

				}

			}, (response) => { });
		},

		//调整部门
		updateDept: function() {
			this.$data.tzDeptKey = '';
			if (this.$data.multipleSelection.length == 1) {
				var data = this.$data.multipleSelection[0];
				this.$data.checkDeptKey = [];
				// this.queryCheckedRole(data.id, "0");
				this.$data.currentUser = data.id;
				this.$data.deptShow = true;
			} else {
				this.$message.error("请选择一条数据")
			}


		},
		//点击部门树时切换
		checkedDept: function(data) {
			this.$data.tzDeptKey = data.id;

		},

		//保存调整后的部门
		saveTzDept: function() {
			if (this.$data.tzDeptKey != '' && this.$data.currentUser != '') {
				debugger;
				this.$http({
					method: 'POST',
					url: this.API_ROOT + '/rbac/user/updateDept',
					body: [{}],
					params: {
						userId: this.$data.currentUser,
						deptId: this.$data.tzDeptKey
					}
				}).then(function(resp) {
					this.$message(resp.data.msg);
					if (resp.data.success) {
						this.queryDeptUser();
						this.$data.deptShow = false;

					}

				}, function(error) {
					// error
				})
			}
		},
		//分配资源角色
		editResRole: function() {
			if (this.$data.multipleSelection.length == 1) {
				var data = this.$data.multipleSelection[0];
				this.$data.checkedResRoleKey = [];
				this.queryResRoleTree();
				this.queryCheckedRole(data.id, "0");
				this.$data.currentUser = data.id;
				this.$data.resRoleShow = true;
			} else {
				this.$message.error("请选择一条数据")
			}


		},
		//保存资源角色
		saveResRole: function() {

			var checkNodes = this.$refs.resRoleTree.getCheckedKeys();
			var data = {
				data: JSON.stringify(checkNodes),
			}
			debugger;
			this.$http({
				method: 'POST',
				url: this.API_ROOT + '/rbac/user/saveRole',
				body: checkNodes,
				params: {
					id: this.$data.currentUser,
					type: "0"
				}
			}).then(function(resp) {
				this.$message(resp.data.msg);
				if (resp.data.success) {
					this.$data.resRoleShow = false;
				}
			}, function(error) {
				// error
			})

		},
		//分配数据角色
		editDataRole: function() {
			if (this.$data.multipleSelection.length == 1) {
				var data = this.$data.multipleSelection[0];
				this.$data.checkedDataRoleKey = [];
				this.$data.currentUser = data.id;
				this.queryDataRoleTree();
				this.queryCheckedRole(data.id, "1");
				this.$data.dataRoleShow = true;
			} else {
				this.$message.error("请选择一条数据")
			}
		},
		//保存数据角色
		saveDataRole: function() {
			var checkNodes = this.$refs.dataRoleTree.getCheckedKeys();
			var data = {
				data: JSON.stringify(checkNodes),
			}
			debugger;
			this.$http({
				method: 'POST',
				url: this.API_ROOT + '/rbac/user/saveRole',
				body: checkNodes,
				params: {
					id: this.$data.currentUser,
					type: "1"
				}
			}).then(function(resp) {
				this.$message(resp.data.msg);
				if (resp.data.success) {
					this.$data.dataRoleShow = false;
				}
			}, function(error) {
				// error
			})

		},
		//分配资源
		editRes: function() {
			if (this.$data.multipleSelection.length == 1) {
				var data = this.$data.multipleSelection[0];
				this.$data.checkedResKey = [];
				this.queryCheckRes(data.id);
				this.$data.currentUser = data.id;
				this.$data.resTreeShow = true;
			} else {
				this.$message.error("请选择一条数据")
			}


		},
		//保存资源
		saveRes: function() {
			var checkNodes = this.$refs.resTree.getCheckedKeys();
			var data = {
				data: JSON.stringify(checkNodes),
			}
			debugger;
			this.$http({
				method: 'POST',
				url: this.API_ROOT + '/rbac/user/saveRes',
				body: checkNodes,
				params: {
					id: this.$data.currentUser
				}
			}).then(function(resp) {
				this.$message(resp.data.msg);
				if (resp.data.success) {
					this.$data.resTreeShow = false;
				}
			}, function(error) {
				// error
			})

		},
		//修改密码
		editPass: function() {
			if (this.$data.multipleSelection.length == 1) {
				var data = this.$data.multipleSelection[0].id;
				this.$data.passFormData.newPass = '';
				this.$data.passFormData.confirmPass = '';
				this.$data.passFormData.id = data;
				this.$data.passFormShow = true;
			} else {
				this.$message.error("请选择一条数据")
			}
		},
		//保存密码
		savePass: function() {
			this.$refs.passForm.validate(function(valid) {
				if (valid) {
					var newPass = this.$data.passFormData.newPass;
					var confirmPass = this.$data.passFormData.confirmPass;
					var id = this.$data.passFormData.id;
					if (newPass != confirmPass) {
						this.$message.error("两次输入不一致，请重新输入！")
						return;
					}
					newPass = md5(newPass);

					this.$http({
						method: 'POST',
						url: this.API_ROOT + '/rbac/user/savePass',
						params: {
							id: id,
							pass: newPass
						}
					}).then(function(resp) {
						if (resp.data.success) {
							this.$message(resp.data.msg);
							this.$data.passFormShow = false;
						} else {
							this.$message.error(resp.data.msg);
						}
					}, function(error) {
						// error
					});

				}
				return false;
			}.bind(this));
		},

		//状态转换
		statusCov: function(row, column) {
			return row.uStatus == 1 || row.uStatus == "1" ? "已启用" : "已停用";
		},

		//性别转换
		sexCov: function(row, column) {
			return row.uSex == 1 || row.uSex == "1" ? "女" : "男";
		},
		//时间转换
		//日期转换
		timeCov: function(row, column) {
			if (row.createTime == "" || row.createTime == null) return "";
			return this.moment(Number(row.createTime)).format("YYYY-MM-DD");
		},

		//部门树过滤
		deptTreeFilter: function() {
			if (this.$data.deptFilterValue == "") {
				this.$message("请输入查询条件");
				this.queryDeptTree();
				return;
			}
			this.$refs.deptTree.filter(this.$data.deptFilterValue);
		},
		//资源过滤
		filterNode: function(value, data, node) {
			if (!value) return true;
			return data.oName.indexOf(value) !== -1 || data.oShortName.indexOf(value) !== -1;
		},

	},

	//组件创建时
	created: function() {
		//查询部门树
		this.queryDeptTree();
		this.queryResTree();
		this.queryTzDeptTree();

	}

};
</script>
<style>

</style>